$(function(){
	var n=$('#imgSlider li').length;//图片张数
	var width =$('#imgSlider').find('img').width();
	var height =$('#imgSlider').find('img').height();
	
	$("<div id='slider_Num'></div>").appendTo('#imgSlider');	//生成数字列表
	$('#imgSlider').css({
		"display":"block",
		"width":width,
		"height":height,
		"position":"relative",
		"overflow":"hidden",
		"margin-left":"auto",
		"margin-right":"auto"
	});								//定义css使图片列表居中显示
	$('#slider_Num').css({
		"width":27*n,
		"height":"20px",
		"position":"absolute",
		"right":"0",
		"bottom":"0"
	});			
	$('#imgContainer').css({
		"width":width*n,				   
		"position":"absolute",
		"left":"0px",
		"top":"0px"
	});
	//添加图片列表及图片链接
	
	var num = 1;
	for(num;num<=n;num++)
		{
		$("<a href='javascript:;'>"+num+"</a>").appendTo("#slider_Num");
		}
	
	
	//图片滚动
	
	var slider =$("#imgSlider"),
		imgs = slider.find('#imgContainer');
		dots = $("#slider_Num").find("a");
		
	var interval = 4000,			//图片切换间隔（毫秒）
		speed = 300,				//动画速度（毫秒）
		autoLock = true;		//是否自动滚动

		
	dots.eq(0).addClass("current");
		
	var scroll =function(){
	  var index =$("#slider_Num").find('.current').index();
		
	  if (index < n -1 ) {
	  index = index + 1;
		  }
	  else {
		  index = 0;
		  }
		  var span = index * width;	
		
		  dots.eq(index).addClass('current').siblings().removeClass('current');
		  imgs.animate({"left":-span+'px'}, speed, function() {		
			  autoStart();
		  	});
		};
		
		
	autoStart = function() {
		if (autoLock !== false) {
			timer = window.setTimeout(function() {
				scroll();
			}, interval);
		}
	};
		
		
	autoStart();
	//点击事件
	dots.click(function() {
		
		if (!$(this).hasClass('current')) {
			
			window.clearTimeout(timer);
			
			var index = $(this).index();
			var span = index * width;
			
			imgs.stop().animate({left:-span+'px'}, 300, function() {
				
				autoStart();
				
			});
			
			$(this).addClass('current').siblings().removeClass('current');
			
		}
		
	});
});